//
// Created by macro on 2020/1/12.
//

#ifndef CPPLEARN_MYQUEUE_H
#define CPPLEARN_MYQUEUE_H

#endif //CPPLEARN_MYQUEUE_H
//
// Created by macro on 2020/1/12.
//
#include <iostream>
#define CAPACITY 5

using namespace std;


typedef struct queue{
    int length;
    int front;
    int rear;
    int data[CAPACITY];
}Queue;


void Init(Queue* ptr) { //初始化队列
    ptr->length = 0;
    ptr->front = 0;
    ptr->rear = -1;
}

// 判断是不是满了
bool QueueFull(Queue* prt){
    return prt ->length == CAPACITY;
}

bool QueueEmpty(Queue* prt){
    return prt -> length == 0;
}

// 入队
bool enQueue(Queue* prt, int e){
    if (QueueFull(prt)){
        return false;
    } else{
        prt -> length += 1;
        prt -> rear = (prt -> rear + 1 % CAPACITY);
        prt -> data[prt->rear] = e;
    }
    return true;
}

// 出队
bool DeQueue(Queue* prt){
    if(QueueEmpty(prt)){
        return false;
    } else{
        // prt -> front -= 1; // 无休止的加下去
        prt -> front = (prt->front +1 % CAPACITY);
        prt -> length +=1;

    }
    return true;
}

// 队列的大小
int QueueSize(Queue* prt){
    return prt -> length;
}

void showQueue(Queue* prt){
    if (QueueEmpty(prt)){
        return;
    } else{
        int i = prt ->front;
        while (i !=prt->rear){
            i++;
            i%CAPACITY;
        }
        cout << prt->data[prt->rear] << " ";
    }
    cout <<endl;
}

